//
//  sizeView.m
//  1243
//
//  Created by ym on 16/7/7.
//  Copyright © 2016年 1243. All rights reserved.
//

#import "sizeView.h"
@interface sizeView ()
{
    int tempWith;
}
@property (nonatomic,strong)UILabel *nameLabel;
@property(nonatomic,strong)UIButton *btn;
@end
@implementation sizeView

- (instancetype)initWithFrame:(CGRect)frame{
    self =  [super initWithFrame:frame];
    if (self) {
        tempWith = 0;
        [self creatLabel];
    }
    
    return self;
}


- (void)creatLabel{
    self.nameLabel = [[UILabel alloc] init];
    [self addSubview:self.nameLabel];
    self.nameLabel.layer.borderColor = [[UIColor grayColor]CGColor];
    self.nameLabel.layer.borderWidth = 0.5f;
        self.nameLabel.layer.masksToBounds = YES;
    
   

    
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.nameLabel.frame = CGRectMake(10, 0, 50, 30);
    self.nameLabel.text = self.dic[@"key"];
    
    for (NSInteger i  = 0; i < [self.dic[@"value"] count]; i++) {
        self.btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:self.btn];
         [self.btn setTitle:[NSString stringWithFormat:@"%@",self.dic[@"value"][i]] forState:UIControlStateNormal];
        CGSize maximumLabelSize = CGSizeMake(1000, 9999);//labelsize的最大值
       //关键语句
      CGSize expectSize = [self.btn sizeThatFits:maximumLabelSize];
         self.btn.frame = CGRectMake(70 + tempWith +10 * i , 0, expectSize.width,30);
        tempWith += expectSize.width;
        
//        if (tempWith > WIDTH - 70) {
//            self.btn.frame = CGRectMake(70 + tempWith +10 * i , 60, expectSize.width,30);
//        }
       
        [self.btn setBackgroundColor:[UIColor yellowColor]];
        [self.btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        NSLog(@"%d",tempWith);
        
    }
    
 
}

@end
